clear all
set matsize 5000

use "${datapath}/fascism_mod_elections_db.dta",clear


foreach var of varlist left c_right far_right far_left  {
egen z_`var' = std(`var')
foreach i of numlist 1/19 {
egen z_`var'`i'=std(`var') if election==`i'
}
}

egen z_fascist1924_vv = std(fascist1924_vv) 
egen z_foots_pop6m = std(foots_pop6m) 


la var z_left			"Left"
la var z_c_right		"Centre-right"
la var z_far_left		"Extreme left"
la var z_far_right		"Extreme right"
la var z_fascist1924_vv		"Fascist vote share in 1924"
la var z_fascism_index		"Fascism index 1920-24"
la var election			"election"
foreach i of numlist 1/19 {
la var z_left`i'		"Left"
la var z_c_right`i'		"Centre-right"
la var z_far_left`i'		"Extreme left"
la var z_far_right`i'		"Extreme right"
}


local cntrls "lpop1911_1-bourgeoisie_19 d_reg* d_elec* province*"


foreach depvar of varlist z_left z_c_right z_far_left z_far_right{
qui ivreg2 `depvar' (z_fascism_index=z_foots_pop6m) `cntrls', partial(d_reg* d_elec* province*) cl(comune1921)
outreg2 using "${outpath}/TAB_A22A_`depvar'.tex", dec(2) keep(z_fascism_index) addstat("Number of clusters", e(N_clust), "1st stage F-stat", e(widstat))  nocons label noaster replace
}


foreach election of numlist 1/9{
foreach depvar of varlist z_left z_c_right z_far_left z_far_right{
if (`election'==1 & `depvar' ==z_far_right)|(`election'==3 & `depvar' ==z_far_left)|(`election'==4 & `depvar' ==z_far_left)|(`election'==5 & `depvar' ==z_far_left) {
}
else {
ivreg2 `depvar'`election' (z_fascism_index=z_foots_pop6m) `cntrls' if election==`election', partial(d_reg* d_elec* province*) cl(circondario1921)
outreg2 using "${outpath}/TAB_A22A_`depvar'.tex", dec(2) keep(z_fascism_index) addstat("Number of clusters", e(N_clust), "1st stage F-stat", e(widstat)) nocons label noaster append
}
}
}

foreach election of numlist 10/19{
foreach depvar of varlist z_left z_c_right z_far_left z_far_right{
if (`election'==13 & `depvar' ==z_far_right) {
}
else {
qui ivreg2 `depvar'`election' (z_fascism_index=z_foots_pop6m) `cntrls' if election==`election', partial(d_reg* d_elec* province*) cl(circondario1921)
outreg2 using "${outpath}/TAB_A22B_`depvar'.tex", dec(2) keep(z_fascism_index) addstat("Number of clusters", e(N_clust), "1st stage F-stat", e(widstat)) nocons label noaster append
}
}
}
